package com.example.controller;

import com.example.common.Result;
import com.example.entity.ActivityRecord;
import com.example.service.ActivityRecordService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/activityRecord")
public class ActivityRecordController {
    @Autowired
    private ActivityRecordService activityRecordService;

    @GetMapping("/selectPage")
    public Result selectPage(@RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize,
                             ActivityRecord activityRecord){
        PageInfo<ActivityRecord> activityRecordPageInfo=activityRecordService.selectPage(pageNum,pageSize,activityRecord);
        return Result.success(activityRecordPageInfo);
    }

    @GetMapping("/selectAll")
    public Result selectAll(ActivityRecord activityRecord){
        List<ActivityRecord> list=activityRecordService.selectAll(activityRecord);
        return Result.success(list);
    }



    @PostMapping("/add")
    public Result add(@RequestBody ActivityRecord activityRecord){
        activityRecordService.add(activityRecord);
        return Result.success();
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        activityRecordService.delete(id);
        return Result.success();
    }

    @PutMapping("/update")
    public Result update(@RequestBody ActivityRecord activityRecord){
        activityRecordService.update(activityRecord);
        return Result.success();
    }

}
